package com.jk.service.impl;

import com.jk.dao.DepartmentMapper;
import com.jk.dto.Tree;
import com.jk.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author yzf
 * @version 1.0
 * @ClassName DepartmentServiceImpl
 * @program: office
 * @description: TODO
 * @date 2025/2/13 20:14
 */
@Service
public class DepartmentServiceImpl implements DepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;

    @Override
    public List<Tree> findDepartmentTree(Tree tree) {
        Long pid = 0L;
        List<Tree> treeList = getNodesData(pid);
        return treeList;
    }

    private List<Tree> getNodesData(Long pid) {
        List<Tree> list = departmentMapper.getNodesData(pid);
        for (Tree point : list) {
            Long id = point.getId();
            List<Tree> children = getNodesData(id);
            point.setChildren(children);
        }
        return list;
    }


}
